package com.oa.entities;

import com.oa.domain.UndeleteEntity;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.HashSet;
import java.util.Set;

/**
 * @name 岗位的实体类
 * @author Yang
 * @date 2018-07-10
 * @version 1.0.1
 */
@Entity
@Table(name = "oa_position")
public class Position extends UndeleteEntity<Long> {
    /**
     *
     */
    private static final long serialVersionUID = 4480492791692598934L;

    /** 岗位的名称 **/
    public static final String POSITION_NAME="name";

    /** 名称 **/
    private String name;

    /** 描述 **/
    private String content;

    /** 上级岗位 **/
    private Position parent;

    /** 创建时间 **/
    private Long date;

    private Set<Position> positions= new HashSet<>();

    @Override
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Long getId() {
        return super.getId();
    }

    @Override
    public void setId(Long id) {
        super.setId(id);
    }

    @NotNull
    @Length(max = 32)
    @Column(name = "position_name",length = 32, nullable = false)
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "position_content")
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "parent_id",updatable = false,insertable = false)
    public Position getParent() {
        return parent;
    }

    public void setParent(Position parent) {
        this.parent = parent;
    }

    @Column(name = "position_date",nullable = false)
    public Long getDate() {
        return date;
    }

    public void setDate(Long date) {
        this.date = date;
    }

    @OneToMany(fetch = FetchType.LAZY,cascade = CascadeType.ALL,mappedBy = "parent")
    public Set<Position> getPositions() {
        return positions;
    }

    public void setPositions(Set<Position> positions) {
        this.positions = positions;
    }

    @Override
    public String toString() {
        return "Position{" +
                "name='" + name + '\'' +
                ", content='" + content + '\'' +
                ", date=" + date +
                '}';
    }
}
